Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loosen lifetime bounds on accessing named captures via Index. #143

Closed
wants to merge 2 commits into from

Conversation

jld
Copy link
Contributor

@jld jld commented Dec 18, 2015

The current definition equates the lifetime of the strings being
matched/captured and the string used as the capture name. The latter
is usually 'static (string literals), which leads to confusing
[borrow-check errors][err] on reasonable-looking code.

This change declares the two lifetimes as separate; this should be a
strict increase in the set of impl instances, so it's a minor version
bump.

[err][]: https://gist.github.com/jld/476a13a00ad05bd99a63

@@ -970,11 +970,11 @@ impl<'t> Index<usize> for Captures<'t> {
///
/// # Panics
/// If there is no group named by the given value.
impl<'t> Index<&'t str> for Captures<'t> {
impl<'t, 'i> Index<&'i str> for Captures<'t> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a bit of documentation here that briefly describes what the 'i lifetime parameter stands for? Thanks! (The 't lifetime should also be documented, e.g., http://doc.rust-lang.org/regex/regex/struct.FindMatches.html)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point; thanks.

While I'm editing the docs: I noticed that the str can't outlive the Captures if it's obtained through either Index impl; should that be a separate PR? It's a little surprising, so a warning and advice to use methods instead might be nice. (This is part of the definition of the Index trait — normally a[i] is part of a and can't outlive it — so it can't be fixed without changing the Output type to &'t str and breaking compatibility.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jld So sorry I missed this comment! You raise a good point. Including those docs in this PR seems fine to me!

@BurntSushi
Copy link
Member

Can't believe I missed this! I have one doc nit, but otherwise looks good to me. Thank you!

The current definition equates the lifetime of the strings being
matched/captured and the string used as the capture name.  The latter
is usually `'static` (string literals), which leads to confusing
[borrow-check errors][err] on reasonable-looking code.

This change declares the two lifetimes as separate; this should be a
strict increase in the set of `impl` instances, so it's a minor version
bump.

[err][]: https://gist.github.com/jld/476a13a00ad05bd99a63
@jld
Copy link
Contributor Author

jld commented Feb 6, 2016

Really sorry for dropping the ball on this. (Also sorry for the rebase / force-push, but I had to fix the version bump.) This version should take care of the doc comment issues.

@@ -1,6 +1,6 @@
[package]
name = "regex"
version = "0.1.48" #:version
version = "0.1.49" #:version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the version bump please? I typically do them in separate commits with tags using a script.

@BurntSushi
Copy link
Member

@jld OK, now I'm the one who has dropped the ball! I left a few more nits. If you like, I can pull your branch and make the changes myself---I feel bad about the back and forth!

BurntSushi added a commit that referenced this pull request Feb 27, 2016
@BurntSushi
Copy link
Member

OK, I just went ahead and merged it in d8fb7f1. Thanks!

@BurntSushi BurntSushi closed this Feb 27, 2016
@BurntSushi
Copy link
Member

Released on crates.io in 0.1.55.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants